using System.Linq;

using vurfu.DataContracts;
using vurfu.Linq;
using vurfu.Repositories.Interfaces;

namespace vurfu.Repositories
{
    public class EventRepository : IEventRepository
    {
        public EventRecord GetEventRecord(string eventId)
        {
            EventRecord eventRecord;
            using (var connection = DataContextFactory.Create())
            {
                eventRecord = (from user in connection.GetTable<EventRecord>()
                              where user.EventId == eventId
                              select user).First();
            }
            return eventRecord;
        }

        public void SaveEventRecord(EventRecord eventRecord)
        {
            using (var connection = DataContextFactory.Create())
            {
                connection.GetTable<EventRecord>().InsertOnSubmit(eventRecord);
                connection.SubmitChanges();
            }
        }
    }
}